package com.ktgj.train.api.factory;

import com.ktgj.common.core.domain.R;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.train.api.RemoteTrainService;
import com.ktgj.train.api.domain.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 *  * 火车票服务降级处理
 * @author ruoyi
 */
@Component
public class RemoteTrainFallbackFactory implements FallbackFactory<RemoteTrainService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteTrainFallbackFactory.class);

    @Override
    public RemoteTrainService create(Throwable cause) {
        log.error("火车票服务调用失败:{}", cause.getMessage());
        return new RemoteTrainService() {

            @Override
            public TrContactQueryResponseApi contactQuerys(TrContactQueryRequestApi request) {
                log.error("查询12306常用联系人失败", cause.getMessage());
                return null;
            }

            @Override
            public BigDecimal seatPrice(SeatPriceApi price) {
                log.error("获取指定座位价格失败！", cause.getMessage());
                return null;
            }

            @Override
            public List<TrainOrderApi> trainOrderNum(Map<String, Object> map) {
                log.error("获取火车票订单量失败！", cause.getMessage());
                return null;
            }

            @Override
            public TrainAccountApi queryAccountIdCrm(Map<String, Object> map) {
                log.error("获取火车票12306账号密码失败！", cause.getMessage());
                return null;
            }

            @Override
            public int queryTrainOrderNumber(Long customerId) {
                log.error("获取会员下有多少笔火车票订单失败！", cause.getMessage());
                return 0;
            }

            @Override
            public JourneyTrainOrderVoApi journeyTrainOrder(Map<String, Object> map) {
                log.error("获取行程火车票订单失败！", cause.getMessage());
                return null;
            }

            @Override
            public String selectCityId(Map<String, Object> map) {
                log.error("获取火车站三字码失败！", cause.getMessage());
                return null;
            }

            @Override
            public TrainTrainstationApi selectCityName(Map<String, Object> map) {
                log.error("获取火车站名称失败！", cause.getMessage());
                return null;
            }

            @Override
            public CityVoApi cityVo(CityVoApi cityVoApi) {
                log.error("获取城市信息失败！", cause.getMessage());
                return null;
            }

            @Override
            public R<TrainOrder> getInfo(Map<String, Long> map) {
                return R.fail("获取订单详细信息失败" + cause.getMessage());
            }

            @Override
            public R<AjaxResult> edit(TrainOrder trainOrder) {
                return R.fail("修改订单失败" + cause.getMessage());
            }

            @Override
            public List<TrainOrderRefundrecord> queryTrainOrderRefundrecordList(Long orderId, String changeType) {
                log.error("查询退票记录列表失败！", cause.getMessage());
                return null;
            }

            @Override
            public List<TrainOrderCRM> orderList(TrainCRMOrder order) {
                return null;
            }

            @Override
            public TrainOrder orderNum(Map<String, Object> map) {
                return null;
            }

            @Override
            public List<TrainOrder> orderListThings()
            {
                return null;
            }
        };
    }
}
